Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethersproject/contracts

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/contracts

Contract abstraction meta-class for ethers.

  • 5.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @ethersproject/contracts?

@ethersproject/contracts is a part of the ethers.js library, which is a complete and compact library for interacting with the Ethereum blockchain and its ecosystem. The @ethersproject/contracts package specifically provides utilities for interacting with smart contracts, including deployment, function calls, and event listening.

What are @ethersproject/contracts's main functionalities?

Deploying a Contract

This feature allows you to deploy a smart contract to the Ethereum blockchain. The code sample demonstrates how to use the ContractFactory to deploy a contract using its ABI and bytecode.

const { ethers } = require('ethers');
const bytecode = '0x...'; // Contract bytecode
const abi = [ /* Contract ABI */ ];
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
const factory = new ethers.ContractFactory(abi, bytecode, wallet);

async function deployContract() {
  const contract = await factory.deploy();
  await contract.deployed();
  console.log('Contract deployed at:', contract.address);
}
deployContract();

Interacting with a Deployed Contract

This feature allows you to interact with an already deployed contract. The code sample shows how to call a function on the contract and read data from it.

const { ethers } = require('ethers');
const abi = [ /* Contract ABI */ ];
const contractAddress = '0x...';
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
const contract = new ethers.Contract(contractAddress, abi, provider);

async function readData() {
  const data = await contract.someFunction();
  console.log('Data:', data);
}
readData();

Listening to Contract Events

This feature allows you to listen to events emitted by a smart contract. The code sample demonstrates how to set up an event listener for a specific event emitted by the contract.

const { ethers } = require('ethers');
const abi = [ /* Contract ABI */ ];
const contractAddress = '0x...';
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
const contract = new ethers.Contract(contractAddress, abi, provider);

contract.on('SomeEvent', (arg1, arg2, event) => {
  console.log('Event received:', arg1, arg2, event);
});

Other packages similar to @ethersproject/contracts

Keywords

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc